<?php

use yii\db\Migration;
use yii\db\Schema;

class m170630_060910_CREAT_TABLE_LOG extends Migration
{
    public function up()
    {
       $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        // 操作日志
        $this->createTable('logs', [
            "id" =>         Schema::TYPE_PK,
            "code" =>     	Schema::TYPE_STRING.   "(12) DEFAULT  NULL COMMENT '关联订单 航线 code'",
            "type" =>       Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1订单 2航线'",
            "oper_type" =>  Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '操作类型 创建、添加优惠、修改...'",
            "desc" =>       Schema::TYPE_STRING.    "(128) NULL COMMENT '描述'",
            "params" =>     Schema::TYPE_STRING.    "(128) NULL COMMENT '参数 json'",
            "user_id" =>    Schema::TYPE_INTEGER.   "(9) DEFAULT  '0' COMMENT '操作人ID'",
            "created_at" => Schema::TYPE_DATETIME. " NULL",
            //"updated_at" => Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);


        $this->createIndex("type_logs", "logs", "type");
        $this->createIndex("code_logs", "logs", "code");

    }

    public function down()
    {
        echo "m170630_060910_CREAT_TABLE_LOG cannot be reverted.\n";

        return false;
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}
